package com.wd.attend.controller.bussiness;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wd.common.core.controller.BaseController;
import com.wd.common.core.domain.HttpResponse;
import com.wd.common.annotation.Log;
import com.wd.common.enums.BusinessType;
import com.wd.attend.domain.AttendRecord;
import com.wd.attend.service.IAttendRecordService;
import com.wd.common.utils.poi.ExcelUtil;

/**
 * 考勤记录Controller
 * 
 * @author liumingkun
 * @date 2023-11-07
 */
@RestController
@RequestMapping("/attend/record")
public class AttendRecordController extends BaseController
{
    @Resource
    private IAttendRecordService attendRecordService;

    /**
     * 查询考勤记录列表
     */
    @PreAuthorize("@ss.hasPermi('attend:record:list')")
    @GetMapping("/list")
    public HttpResponse list(AttendRecord attendRecord)
    {
        startPage();
        List<AttendRecord> list = attendRecordService.selectAttendRecordList(attendRecord);
        return HttpResponse.successData(getDataTable(list));
    }

    /**
     * 导出考勤记录列表
     */
    @PreAuthorize("@ss.hasPermi('attend:record:export')")
    @Log(title = "考勤记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendRecord attendRecord)
    {
        List<AttendRecord> list = attendRecordService.selectAttendRecordList(attendRecord);
        ExcelUtil<AttendRecord> util = new ExcelUtil<AttendRecord>(AttendRecord.class);
        util.exportExcel(response, list, "考勤记录数据");
    }

    /**
     * 获取考勤记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('attend:record:query')")
    @GetMapping(value = "/{recordId}")
    public HttpResponse getInfo(@PathVariable("recordId") Long recordId)
    {
        return successData(attendRecordService.selectAttendRecordByRecordId(recordId));
    }

    /**
     * 新增考勤记录
     */
    @PreAuthorize("@ss.hasPermi('attend:record:add')")
    @Log(title = "考勤记录", businessType = BusinessType.INSERT)
    @PostMapping
    public HttpResponse add(@RequestBody AttendRecord attendRecord)
    {
        return getResult(attendRecordService.insertAttendRecord(attendRecord));
    }

    /**
     * 修改考勤记录
     */
    @PreAuthorize("@ss.hasPermi('attend:record:edit')")
    @Log(title = "考勤记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public HttpResponse edit(@RequestBody AttendRecord attendRecord)
    {
        return getResult(attendRecordService.updateAttendRecord(attendRecord));
    }

    /**
     * 删除考勤记录
     */
    @PreAuthorize("@ss.hasPermi('attend:record:remove')")
    @Log(title = "考勤记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public HttpResponse remove(@PathVariable Long[] recordIds)
    {
        return getResult(attendRecordService.deleteAttendRecordByRecordIds(recordIds));
    }
}
